using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using BoOnce.Components;
using BoOnce.GameLogic;
using BoOnce.GameLogic.Entities;
using BoOnce.Helpers;
using BoOnce.Core.Components;

namespace BoOnce.GameLogic.Entities
{
    class BusPlayer : Player
    {

        #region Constructor
        public BusPlayer(PlayerIndex playerIndex, Vector2 pos, String name, float height, float width, float mass)
            : base(playerIndex, pos, name, height, width, mass)
        {
            if (playerIndex == PlayerIndex.One)
            {
                Camera.FollowedEntity = this;
            }
        
            Add(new Combo(Action.WalkRight,InputComponent.Buttons.Action1,InputComponent.Buttons.Action1,InputComponent.Buttons.Action1));
        }
        #endregion

        /// <summary>
        /// Do the action
        /// </summary>
        /// <param name="action">Action to do</param>
        /// <param name="gameTime">game time structure</param>
        public override void DoAction(Action action, GameTime gameTime)
        {
            switch (action)
            {
                case Action.WalkRight:
                    Position += new Vector2((float)(gameTime.ElapsedGameTime.TotalMilliseconds * _Speed), 0.0f);
                    break;

                case Action.WalkLeft:
                    Position += new Vector2((float)(gameTime.ElapsedGameTime.TotalMilliseconds * -_Speed), 0.0f);
                    break;

                case Action.Jump:
                    Position += new Vector2(0.0f, (float)(gameTime.ElapsedGameTime.TotalMilliseconds * -_Speed));
                    SetAnimation("dead", false, SomebodyPositionState.NORMAL, SomebodyActionState.CAN_BE_INTERRUPT);
                    break;

                case Action.Slide:
                    Position += new Vector2(0.0f, (float)(gameTime.ElapsedGameTime.TotalMilliseconds * _Speed));
                    SetAnimation("hit", false, SomebodyPositionState.NORMAL, SomebodyActionState.CAN_BE_INTERRUPT);
                    break;

                default:
                    Logger.WriteWarning(this, "[" + _Name + "] Somebody.Move(" + action + ") is not yet support");
                    break;
            }
        }

        ///   /// <summary>
        /// Handle new button pressed, and execute associated Action
        /// </summary>
        /// <param name="buttons">button pressed</param>
        /// <param name="gameTime">game time structure</param>
        /// <param name="IsNew">new press</param>
        public override void ButtonHandler(InputComponent.Buttons buttons, GameTime gameTime, Boolean IsNew)
        {
            if(IsNew)
                Add(buttons, gameTime);
            
            switch (buttons)
            {
                case InputComponent.Buttons.Left:
                    DoAction(Action.WalkLeft, gameTime);
                    break;

                case InputComponent.Buttons.Right:
                    DoAction(Action.WalkRight, gameTime);

                    break;

                case InputComponent.Buttons.Up:
                    DoAction(Action.Jump, gameTime);
                    break;

                case InputComponent.Buttons.Down:
                    DoAction(Action.Slide, gameTime);
                    break;

                default:
                    //Logger.WriteWarning(this, "The button '" + buttons + "' is not already binded");
                    break;

            }
        }
    }
}
